import { Injectable } from '@angular/core';
import { DataService } from './data.service';
declare var $: any;
@Injectable({
  providedIn: 'root'
})
export class AppdataService {

  public state: {
    current: any,
    progress: number,
  }
  suspendData: {
    cvtData,
    currentPage,
    principle,
    capacityPrinciple,
    diagnostic,
    instruction,
    testedCache: any,
    questionCache: any,
    elsaWinCache: any,
    router: string,
  };
  constructor(
    public data: DataService,
  ) { 
    this.state = {
      current: {},
      progress: 0,
      // publishProgress: 0,
      // isPass: true,
    };
    this.suspendData = {
      'cvtData': this.data,
      'currentPage': 1,

      'capacityPrinciple': {},
      'principle': {},
      'instruction': {},
      'diagnostic': {},
      'testedCache': {},
      'questionCache': {},
      'elsaWinCache': {},
      router: '',
    };
    this.initState();
  }

  initState() {
    let saved = 1;
    $.xcj.scorm.api.loadPage();
    if ($.xcj.scorm.api.getComplete() !== 'incomplete' &&
        $.xcj.scorm.api.getComplete() !== 'completed') {
        $.xcj.scorm.api.setComplete('not attempted');
        $.xcj.scorm.api.doCommit();
    }

    const rePage = $.xcj.scorm.api.getSuspendData();
    if (rePage && rePage !== 'false') {
      console.log('获取保存的数据----当前有数据');
      let getSaveData = JSON.parse(rePage);
      this.data.Catalog = getSaveData.cvtData.Catalog;
      this.data.content = getSaveData.cvtData.content;
      this.data.currentPage = getSaveData.cvtData.currentPage;
    }
    this.state.progress = saved;
  }





}
